﻿using Marmat.Foundation;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Marmat.Template.WinForm
{
    public partial class ChangePasswordForm : Marmat.Forms.Form, Marmat.Foundation.IChangePasswordForm
    {
        private readonly IChangePassword changePassword;
        internal Marmat.Foundation.IRoleEntity[] roleCollection;

        public ChangePasswordForm(Marmat.Foundation.IChangePassword changePassword)
        {
            InitializeComponent();
            this.changePassword = changePassword;
        }

        public bool ShowDialog(string user_id)
        {
            this.textBox1.Value = user_id;
            return this.ShowDialog() == DialogResult.OK;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.requiredComponent1.Verify())
            {
                if (!string.Equals(this.textBox3.Value, this.textBox4.Value))
                {
                    this.labelControl1.Text = "您二次输入的密码不一致。";
                    return;
                }
                try
                {
                    this.labelControl1.Text = "";
                    this.changePassword.Submit(this.textBox1.Value, this.textBox2.Value, this.textBox4.Value);
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    this.labelControl1.Text = ex.GetBaseException().Message;
                }
            }
        }
    }
}
